package com.situ.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.situ.web.entity.Student;
import com.situ.web.exception.NameAlreadyExistException;
import com.situ.web.service.IStudentService;
import com.situ.web.service.impl.StudentServiceImpl;

public class TianJiaStudentServlet extends HttpServlet{
	private IStudentService studentService = new StudentServiceImpl();
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String name = req.getParameter("name");
		String age = req.getParameter("age");
		String gender = req.getParameter("gender");
		Student student = new Student(name, Integer.parseInt(age), gender);
		boolean result = false;
		try {
			result = studentService.regist(student);
		} catch (NameAlreadyExistException e) {
			e.printStackTrace();
		}
		resp.sendRedirect(req.getContextPath() + "/studentList");
	}

}
